﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Alex.Library.Cloud.Libs;

namespace Alex.Library.Cloud.VMWare.V51.VMMParameters
{
    public class CreateVMParameter : IVMMParameter
    {
        public CreateVMParameter()
        {
            this.CPUCount = 1;
            this.DiskSize = 1024;
            this.MemorySize = 1024;            
        }
        
        public string VMName { get; set; }
        public string DatacenterName { get; set; }
        public string HostName { get; set; }
        public string GuestOsId { get; set; }
        public string DataStoreName { get; set; }
        /// <summary>
        /// the new VM cpu count. default(1).
        /// </summary>
        public int CPUCount { get; set; }
        /// <summary>
        /// the new VM disk size(MB). default(1024MB);
        /// </summary>
        public int DiskSize { get; set; }
        /// <summary>
        /// the new VM memory size(MB). default(1024MB);
        /// </summary>
        public int MemorySize { get; set; }

        public string ErrorMessage { get; private set; }

        public bool IsValid()
        {
            bool isvalid = true;
            StringBuilder sb = new StringBuilder();
            
            if (String.IsNullOrEmpty(VMName))
            {
                sb.AppendLine("VMName is empty or null.");
                isvalid = false;
            }
            if (String.IsNullOrEmpty(DatacenterName))
            {
                sb.AppendLine("DatacenterName is empty or null.");
                isvalid = false;
            }
            if (String.IsNullOrEmpty(HostName))
            {
                sb.AppendLine("HostName is empty or null.");
                isvalid = false;
            }
            if (String.IsNullOrEmpty(GuestOsId))
            {
                sb.AppendLine("GuestOsId is empty or null.");
                isvalid = false;
            }
            if (String.IsNullOrEmpty(DataStoreName))
            {
                sb.AppendLine("DataStoreName is empty or null.");
                isvalid = false;
            }
            if (CPUCount < 1)
            {
                sb.AppendLine("CPUCount is not valid.");
                isvalid = false;
            }
            if (DiskSize < 1)
            {
                sb.AppendLine("DiskSize is not valid.");
                isvalid = false;
            }
            if (MemorySize < 1)
            {
                sb.AppendLine("MemorySize is not valid.");
                isvalid = false;
            }

            ErrorMessage = sb.ToString();
            return isvalid;
        }
    }
}
